import jwt
from django.conf import settings
def generate_jwt(payload, secret_key=settings.SECRET_KEY, algorithm='HS256'):
    return jwt.encode(payload, secret_key, algorithm='HS256')
def verify_jwt(token, secret_key=settings.SECRET_KEY):
    try:
        payload = jwt.decode(token, secret_key, algorithms=['HS256'])
        return payload, 0
    except jwt.ExpiredSignatureError:
        return {'message': 'token已过期'}, 1
    except jwt.InvalidTokenError:
        return {'message': 'token无效'}, 1